package services

import (
	"gitee.com/dingdang4D/go-basic-exercises/models"
)

// CRUD 操作
func CreateUser(user *models.User) error {
	return Db.Create(user).Error
}

func GetUserByID(id uint) (*models.User, error) {
	var user models.User
	if err := Db.First(&user, id).Error; err != nil {
		return nil, err
	}
	return &user, nil
}

func UpdateUser(user *models.User) error {
	return Db.Save(user).Error
}

func DeleteUser(id uint) error {
	return Db.Delete(&models.User{}, id).Error
}
